package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import DAL.Entites.Console;
import DAL.JDBC.ConsoleJDBC;
import DAL.JDBC.DBConn;


public class AllConsoles extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public AllConsoles() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ConsoleJDBC consoleJDBC = new ConsoleJDBC(DBConn.getConnection());	
		List<Console> consolesList = consoleJDBC.listConsoles();

		JSONObject consoles = new JSONObject();
		try {
			consoles.put("consoles", consolesList);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		PrintWriter pw = response.getWriter();
		pw.write(consoles.toString());
	}

}
